package com.burpee.dao;

import java.util.List;

import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.burpee.ui.Chatting;
import com.burpee.ui.ExerciseOrder;

@Repository(value="excerciseorderDao")
public class ExerciseOrderDaoImpl implements ExerciseOrderDao {
	
	SqlSessionTemplate sqlSessionTemplate;

	@Autowired
	public void setSessionTemplate(SqlSessionFactory sqlSessionFactory) {
		this.sqlSessionTemplate = new SqlSessionTemplate(sqlSessionFactory);
	}

	public List<ExerciseOrder> list() {
		List<ExerciseOrder> list = null;

		try {
			list = sqlSessionTemplate.selectList("exerciseorderlist");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return list;
	}

	public ExerciseOrder view(ExerciseOrder exerciseOrder) {
		ExerciseOrder exerciseOrderview = new ExerciseOrder();

		try {
			exerciseOrderview = sqlSessionTemplate.selectOne("exerciseorderview", exerciseOrder);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return exerciseOrderview;
	}

	public int add(ExerciseOrder exerciseOrder) {
		int result = 0;

		try {
			result = (int)sqlSessionTemplate.insert("exerciseorderadd",exerciseOrder);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return result;
	}

	public int modify(ExerciseOrder exerciseOrder) {
		int result = 0;

		try {
			result = (int)sqlSessionTemplate.update("exerciseordermodify",exerciseOrder);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return result;
	}

	public int remove(ExerciseOrder exerciseOrder) {
		int result = 0;

		try {
			result = (int)sqlSessionTemplate.update("exerciseOrderremove",exerciseOrder);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return result;
	}

}
